package com.xyy.saas.payment.adpater.jdCredit.enums;

import lombok.Getter;

/**
 * 编码枚举
 *
 * @author yuchengying
 * @date 2023/12/19
 */
@Getter
public enum CodeEnum {
    SUCCESS("0000000", "成功"),
    FAIL("0000001", "失败"),
    SIGNATURE_VERIFICATION_FAIL("0000002", "验签失败"),
    ALREADY_EXIST("0000003", "记录已存在"),
    NOT_EXIST("0000004", "记录不存在"),
    IS_EMPTY("0000005", "字段为空"),
    FIELD_VALIDATION_FAIL("0000006", "字段验证不通过"),
    ENUM_VALIDATION_FAIL("0000007", "枚举验证失败");

    /**
     * 代码
     */
    private String code;
    /**
     * 信息
     */
    private String msg;

    /**
     * 构造器
     *
     * @param code 代码
     * @param msg  味精
     */
    CodeEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 获取错误代码枚举
     *
     * @param type 类型
     * @return {@link CodeEnum}
     */
    public static CodeEnum getErrorCodeEnum(String type) {
        for (CodeEnum errorCodeEnum : CodeEnum.values()) {
            if (errorCodeEnum.getCode().equals(type)) {
                return errorCodeEnum;
            }
        }
        return null;
    }

}
